import { Injectable } from '@angular/core';
import { RequestClass } from './request.service';
@Injectable()
export class ApiMenuService {
    constructor(private requestclass: RequestClass) {}
    fetchMenuListById = async ({ id }) => {
        return await this.requestclass.request.Pget('/role/roleMenu/' + id);
    };

    fetchApiListById = async ({ id }) => {
        return await this.requestclass.request.Pget('/role/roleApi/' + id);
    };

    saveMenuByList = async ({ id, list }) => {
        return await this.requestclass.request.post('/role/roleMenu/set', {
            params: {
                roleId: id,
            },
            // data: {
            //   sysRoleAndPermissionVos: list,
            // },
            data: list,
        });
    };

    saveApiByList = async ({ id, list }) => {
        return await this.requestclass.request.post('/role/roleApi/set', {
            params: {
                roleId: id,
            },
            // data: {
            //   sysRoleAndPermissionVos: list,
            // },
            data: list,
        });
    };

    fetchMenuListByNone = async () => {
        return await this.requestclass.request.Pget('/menu/getinfos');
    };

    fetchApiListByNone = async () => {
        return await this.requestclass.request.Pget('/api/getinfos');
    };

    addMenuByConfig = async ({
        pid,
        description,
        frontendMenuName,
        frontendMenuSort,
        frontendMenuUrl,
    }) => {
        return await this.requestclass.request.post('/menu/insertmenu', {
            data: {
                frontendMenuName,
                frontendMenuSort,
                frontendMenuUrl,
                description,
                pid,
            },
        });
    };

    addApiByConfig = async ({
        pid,
        description,
        backendApiName,
        backendApiMethod,
        backendApiSort,
        backendApiUrl,
    }) => {
        return await this.requestclass.request.post('/api/insertapi', {
            data: {
                backendApiName,
                backendApiSort,
                backendApiUrl,
                description,
                backendApiMethod,
                pid,
            },
        });
    };

    editMenuByConfig = async ({
        pid,
        description,
        frontendMenuName,
        frontendMenuSort,
        frontendMenuUrl,
        frontendMenuId,
    }) => {
        return await this.requestclass.request.put('/menu/updatemenu', {
            data: {
                pid,
                description,
                frontendMenuName,
                frontendMenuSort,
                frontendMenuUrl,
                frontendMenuId,
            },
        });
    };

    editApiByConfig = async ({
        backendApiName,
        backendApiSort,
        backendApiUrl,
        description,
        backendApiMethod,
        pid,
        backendApiId,
    }) => {
        return await this.requestclass.request.put('/api/updateapi', {
            data: {
                backendApiName,
                backendApiSort,
                backendApiUrl,
                description,
                backendApiMethod,
                pid,
                backendApiId,
            },
        });
    };

    deleteMenuById = async ({ id }) => {
        return await this.requestclass.request.delete('/menu/deletemenu', {
            params: {
                idList: id,
            },
        });
    };

    deleteApiById = async ({ id }) => {
        return await this.requestclass.request.delete('/api/deleteapi', {
            params: {
                idList: id,
            },
        });
    };
}
